﻿Imports BUS
Imports DTO
Public Class CapNhatMonHoc

    Public Sub LayDanhSachMonHoc()
        dtgvdanhsachmonhoc.Rows.Clear()
        Dim _bus As New CMonHocBUS()
        Dim _dsmonhoc As New List(Of CMonHocDTO)
        _dsmonhoc = _bus.LayDanhSachMonHoc()
        Dim i As Integer
        For i = 0 To _dsmonhoc.Count - 1
            dtgvdanhsachmonhoc.Rows.Add(i + 1, _dsmonhoc(i).MaMonHoc, _dsmonhoc(i).TenMonHoc)
        Next

    End Sub

    Private Sub CapNhatMonHoc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LayDanhSachMonHoc()
    End Sub

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub

    Private Sub dtgvdanhsachmonhoc_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtgvdanhsachmonhoc.SelectionChanged

        If dtgvdanhsachmonhoc.CurrentRow.Index >= 0 Then
            txtmonhoc.Text = dtgvdanhsachmonhoc.CurrentRow.Cells("clmonhoc").Value
        End If

    End Sub

    Private Sub btncapnhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncapnhat.Click
        Dim _MHdto As New CMonHocDTO()
        _MHdto.MaMonHoc = dtgvdanhsachmonhoc.CurrentRow.Cells("clmamonhoc").Value
        _MHdto.TenMonHoc = txtmonhoc.Text
        Dim _bus As New CMonHocBUS()

        If _bus.CapNhatMonHoc(_MHdto) > 0 Then
            MessageBox.Show("Cap Nhat Mon Hoc Thanh Cong")
            LayDanhSachMonHoc()
        Else
            MessageBox.Show("Cap Nhat Mon Hoc That Bai")
        End If

    End Sub
End Class